/**
 *
 */
package com.cmcc.awareness;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Date 2018年4月12日 下午7:21:32
 * @author Amish
 *
 */
public class TestRegex {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(regMatch("lvpin",".*lvpi\\x6e.*"));
		System.out.println(regMatch("slvpins",".*lvpin.*"));
		System.out.println(regMatch("sd\nslvpin\rs","(.|\n|\r)*lvpin(.|\n|\r)*"));
		
		System.out.println(regMatch("xxxx3g.qq.comxxxx","(.|\n|\r)*.3g.qq.com(.|\n|\r)*"));
		
		System.out.println(regMatch("xxxx3g.qq.comxxxx","^3g.qq.com(.|\n|\r)*"));
		System.out.println(regMatch("3g.qq.comxxxx","^3g.qq.com(.|\n|\r)*"));
		System.out.println(regMatch("xxxx3g.qq.com","(.|\n|\r)*3g.qq.com$"));
		
		
		/**
		 * (1)检查字符串是否有.，如果有用\\.来替换
		 * (2)检查字符串是否有*，如果有，用.*替换
		 * (3)包含字符串必须前后加上.*（表示包含）
		 */
		System.out.println(regMatch("xxxx3g.qq.combb",".qq.com"));
		System.out.println(regMatch("xxxx3g.qq.combb",".*.qq.com.*"));
		System.out.println(regMatch("xxxx3gaqqacombb",".*.qq.com.*"));//非.也匹配了 需要注意
		System.out.println(regMatch("xxxx3g.qq.combb",".*\\.qq\\.com.*"));//正确写法1
		System.out.println(regMatch("xxxx3gaqqacombb",".*\\.qq\\.com.*"));//保证了非.不被匹配
		
		System.out.println(regMatch("aaaa/lvpin/bbbb",".*/lvpin/.*"));//保证了非.不被匹配
		
		
		
		System.out.println("\\.");
	    String ss = "lvpin.com.cn";
		System.out.println(ss);
		System.out.println(ss.replaceAll(".", "\\."));
		System.out.println(ss.replaceAll("\\.", "\\\\."));
		
		String sss = "lvpin*com*cn";
		System.out.println(sss);
		System.out.println(sss.replaceAll("\\*", ".*"));
		
		String ssss = "0x12345678";
		System.out.println(ssss);
		System.out.println(ssss.replaceAll("0x", ""));

	}
	
	public static boolean regMatch(String str,String regString){
		
		Pattern pattern =Pattern.compile(regString);
		Matcher matcher = pattern.matcher(str);
		return matcher.matches();
	}

}
